package org.hhgzs.modules.erp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hhgzs.modules.erp.entity.DepotHead;
import org.hhgzs.modules.erp.entity.Material;
import org.hhgzs.modules.erp.entity.SerialNumber;
import org.hhgzs.modules.erp.service.DepotHeadService;
import org.hhgzs.modules.erp.service.MaterialService;
import org.hhgzs.modules.erp.vo.DepotHeadVo4InDetail;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 单据主表 前端控制器
 * </p>
 *
 * @author peiqy
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/depotHead")
@Slf4j
@RequiredArgsConstructor
@Api("结算账户管理")
public class DepotHeadController extends JeecgController<DepotHead, DepotHeadService> {

    private final DepotHeadService depotHeadService;

    /**
     * 获取用户列表数据
     *
     * @param data
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @PermissionData(pageComponent = "basedata/DepotList")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation("列表查询")
    public Result<IPage<DepotHeadVo4InDetail>> queryPageList(DepotHeadVo4InDetail data, @RequestParam(value = "organId",required = false) Integer oId,
                                                             @RequestParam(value ="materialParam",required = false) String materialParam,
                                                             @RequestParam(value ="depotId",required = false) Integer depotId,
                                                             @RequestParam(value ="beginTime",required = false) String beginTime,
                                                             @RequestParam(value ="endTime",required = false) String endTime,
                                                             @RequestParam(value ="type",required = false) String type, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<DepotHeadVo4InDetail>> result = new Result<IPage<DepotHeadVo4InDetail>>();
        QueryWrapper<DepotHeadVo4InDetail> queryWrapper = QueryGenerator.initQueryWrapper(data, req.getParameterMap());

        Page<DepotHeadVo4InDetail> page = new Page<>(pageNo, pageSize);
        IPage<DepotHeadVo4InDetail> pageList = depotHeadService.pageX(page, beginTime, endTime, type, materialParam, depotId, oId);

        result.setSuccess(true);
        result.setResult(pageList);
        log.info(pageList.toString());
        return result;
    }

}
